package com.my;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.io.StringWriter;

/**
 * Created by YJH on 2017/7/6 22:57.
 */
public class TestTagFragment extends SimpleTagSupport {

    @Override
    public void doTag() throws JspException, IOException {
        JspFragment fragment = getJspBody();
        //fragment.invoke(Writer);  Writer即为标签体内容输出的字符流，若为null，则输出到getJspContext().getOut(),即输出到页面上

        //1.利用StringWriter得到的标签体的内容.
        StringWriter sw = new StringWriter();
        fragment.invoke(sw);

        //2.把标签体的内容都变为大写
        String content =sw.toString().toUpperCase();

        //3.获取JSP页面的out隐含对象，输出到页面上
        getJspContext().getOut().println(content+"<br/>");
    }
}
